package com.yourenbang.lingyun.transaction.web.controller.petal;

import com.alibaba.fastjson.JSONObject;
import com.yourenbang.lingyun.core.base.controller.BaseController;
import com.yourenbang.lingyun.core.base.interceptor.ExcludeInterceptor;
import com.yourenbang.lingyun.core.message.Result;
import com.yourenbang.lingyun.core.util.KLog;
import com.yourenbang.lingyun.transaction.web.domain.dto.DownloadBillDTO;
import com.yourenbang.lingyun.transaction.web.domain.vo.ALiBillListVO;
import com.yourenbang.lingyun.transaction.web.service.petal.BillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/transaction/bill")
@CrossOrigin("*")
public class AliBillDownloadController extends BaseController {

    @Autowired
    private BillService billService;

    //下载账单（阿里）
    @ExcludeInterceptor
    @PostMapping(value = "/download", produces = {"application/json;charset=UTF-8"})
    public Result<ALiBillListVO> downloadBillAli(@Validated @RequestBody DownloadBillDTO dto, BindingResult br) {
        Result result = verifyParam(br);
        if (!result.isSuccess()) {
            return result;
        }
        KLog.info("[账单下载]下载阿里账单开始...入参:{}",dto.toString());
        return billService.downloadAliBill(dto.getDate());

    }

    //下载账单（klks）
    @ExcludeInterceptor
    @PostMapping(value = "/download/klks/pledge", produces = {"application/json;charset=UTF-8"})
    public Result<JSONObject> downloadKlksBillAli(@Validated @RequestBody DownloadBillDTO dto,
                                                  BindingResult br) {
        Result result = verifyParam(br);
        if (!result.isSuccess()) {
            return result;
        }
        KLog.info("[账单下载]下载klks阿里账单开始...");
        Result<JSONObject> listResult = billService.downloadKlksAliBill(dto.getDate());
        return listResult;
    }
}
